Skip to content

Conversation

@green-arrow
Copy link
Contributor

@green-arrow green-arrow commented Dec 9, 2016

What's in this PR?

Redesigned API to account for the newly updated task list / task front end.

References

Progress on: #554 #553 #555

Total progress

Also added:

* task list filtering for tasks API
* automatically create task lists on project creation - #553

Still remaining:

* Implementing APIs and views
* Implementing tests
@green-arrow green-arrow changed the title Added schema for tasks lists - #554 Updates to task / task list design - #553 #554 #555 Dec 9, 2016
Modified project API / view to return task lists
Modified tasks API to order by rank instead of inserted date
Modified tasks API / view to return task list
Added task list API / view to get all / single task lists
@green-arrow
Copy link
Contributor Author

@joshsmith - this should be ready to review now. Feel free to pull in whoever else you think needs to review this.

@joshsmith
Copy link
Contributor

🎉 thanks @green-arrow. Now that I've spent the past 8 hours or so exploring this problem top-to-bottom, thinking this looks pretty good, but now need to review more thoroughly.

I'm going to be playing around with a quick-and-dirty client implementation and then test out how well these will play together.

Stay tuned for a more thorough review.

If you wanted to move on to something else, please feel free.

@joshsmith joshsmith modified the milestone: Redesign the tasks UI Dec 13, 2016
Copy link
Contributor

@joshsmith joshsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, have some thoughts we can discuss:

def project_id_with_number_filter(query, _), do: query

def task_list_id_with_number_filter(query, %{"id" => number, "task_list_id" => task_list_id}) do
IO.puts "YAY"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs removed.

task_list_ids = task_list_ids |> coalesce_id_string
query |> where([object], object.task_list_id in ^task_list_ids)
end
def task_list_filter(query, %{"task_list_id" => task_list_id}) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this one is necessary. See the id_filter for what I mean.


def sort_by_newest_first(query), do: query |> order_by([desc: :inserted_at])

def sort_by_rank(query), do: query |> order_by([asc: :rank])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this desc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we want rank to be ascending (lower numbers are at the top of the list).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, you're right. sorry.

|> put_assoc(:task_lists, TaskList.default_task_lists())
|> Repo.update

add_existing_tasks_to_inbox(project, hd(project.task_lists))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is hd()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hd/1 refers to the first item in the list, the head. (Also, tl/1 refers to the last item, the tail)

|> Enum.map(&Integer.parse/1)
|> Enum.map(fn({id, _rem}) -> id end)

assert ids == [task_list_2.id, task_list_1.id, task_list_3.id]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we had some id assertion helpers in other controller tests.

task_list_b = insert(:task_list, rank: 500, project: project)
task = insert(:task, rank: 1000, task_list: task_list_a)

rendered_json = render(CodeCorps.TaskListView, "show.json-api", data: [task_list_a, task_list_b])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just render the show here? Seems simpler.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I.e. just one task list, not two.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I was working on seeing if I could work with position in the return and needed multiple items to verify. Since that's not how this works (rank is returned) we can go back to just one.

"data" => [%{
"id" => task_list.id |> Integer.to_string,
"type" => "task-list"
}]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer formatting like below with tasks.

"task-type" => task.task_type,
"title" => task.title,
"updated-at" => task.updated_at,
"rank" => task.rank
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alpha-order here.

end

def record(%Plug.Conn{params: %{"task_list_id" => _task_list_id} = params}, _number_as_id) do
IO.inspect params
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove.

|> validate_inclusion(:task_type, task_types)
|> assoc_constraint(:task_list)
|> apply_position()
|> set_order(:position, :rank, :task_list_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This further makes me think order is the right name here.

@green-arrow
Copy link
Contributor Author

@joshsmith - I gave a 👍 to all the things I fixed and left a couple comments in other places.

@joshsmith
Copy link
Contributor

Looks great! Going to squash and merge if you're ready!

@green-arrow
Copy link
Contributor Author

Have at it!

@joshsmith joshsmith merged commit f8a7f79 into develop Dec 14, 2016
@joshsmith joshsmith deleted the task-redesign branch December 14, 2016 01:17
@joshsmith joshsmith mentioned this pull request Dec 14, 2016
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants